package com.tomcat.myapplication.module;

import com.google.gson.Gson;
import com.tomcat.myapplication.MainActivity;
import com.tomcat.myapplication.bean.DataBean;
import com.tomcat.myapplication.entity.request.MainRequest;
import com.tomcat.myapplication.http.HttpFactory;
import com.tomcat.myapplication.http.HttpProgressSubscriber;
import com.tomcat.myapplication.http.i_http.HttpSubscriberOnNextListener;
import com.tomcat.myapplication.module.IModule.IMainModule;
import com.tomcat.myapplication.presenter.MainPresenter;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class MainModule implements IMainModule {
    MainPresenter presenter;
    MainActivity activity;

    public MainModule(MainPresenter presenter, MainActivity activity) {
        this.presenter = presenter;
        this.activity = activity;
    }
    @Override
    public void getDriverfree(String arriveDT) {
        HttpSubscriberOnNextListener<DataBean> loginListener = new HttpSubscriberOnNextListener<DataBean>() {
            @Override
            public void onNext(DataBean dataBean) {

                presenter.getDriverfreeSuccess(dataBean);

            }

            @Override
            public void onError(String message) {
                presenter.getDriverfreeError(message);
            }
        };

        MainRequest requests = new MainRequest(arriveDT);
        String json = new Gson().toJson(requests);
        RequestBody request = RequestBody.create(MediaType.parse("application/json;charset=UTF-8"),json);
        HttpFactory.getInstance().getDriverfree(new HttpProgressSubscriber<DataBean>(loginListener,activity,true),request);

    }
}
